package com.returnsoft.resource.service;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;

import com.returnsoft.resource.dto.RecruimentSourceDto;
import com.returnsoft.resource.eao.RecruimentSourceEao;
import com.returnsoft.resource.entity.RecruimentSource;
import com.returnsoft.resource.exception.ConversionExcepcion;
import com.returnsoft.resource.exception.EaoExcepcion;
import com.returnsoft.resource.exception.RecruitmentException;
import com.returnsoft.resource.util.Conversion;

/**
 * Session Bean implementation class RecruimentSourceBean
 */
@Stateless
@LocalBean
public class RecruimentSourceBean implements RecruimentSourceInterface {

	@EJB
	private RecruimentSourceEao recruimentSourceEao;

	@EJB
	private Conversion conv;

	@Override
	public List<RecruimentSourceDto> findAll() throws RecruitmentException {
		try {
			List<RecruimentSource> recruimentsSource = recruimentSourceEao
					.findAll();
			List<RecruimentSourceDto> recruimentsSourceDto = new ArrayList<RecruimentSourceDto>();
			for (RecruimentSource recruimentSource : recruimentsSource) {
				RecruimentSourceDto recruimentSourceDto = conv
						.fromRecruimentSource(recruimentSource);
				recruimentsSourceDto.add(recruimentSourceDto);
			}
			return recruimentsSourceDto;
		} catch (EaoExcepcion e) {
			throw new RecruitmentException(e.getMessage());
		} catch (ConversionExcepcion e) {
			throw new RecruitmentException(e.getMessage());
		} catch (Exception e) {
			e.printStackTrace();
			throw new RecruitmentException(e.getMessage());
		}
	}

}
